<html>
<head>
<meta charset="UTF-8">
<title>系统部署信息列表</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<script type="text/javascript">
	var subsCode= $.getUrlParam("subsCode");
	$(function (){
		queryList();
	})

	function queryList(){
		var appCnname=document.getElementById("appCnname").value;
		var appName=document.getElementById("appName").value;
		$('#dg').datagrid({
			queryParams: {
				subsCode: subsCode,
				appCnname:appCnname,
				appName:appName
			}
		});
		$('#dg').datagrid({url : '../../api/sys/deploy/infos'})
	}

	function doAdd(){
		JLEUtil.createModalWin('新增', 'SysDeployInfoAdd.html');
	}
	
	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('修改', 'SysDeployInfoUpdate.html?' + 'appDeployId=' + row.appDeployId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doDelete(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"appDeployId":"' + row.appDeployId + '"'+'}');
					$.restfulDelete('../../api/sys/deploy/info', jsonData, function(data) {
						$.messager.alert('提示','记录删除成功!','info');
						$('#dg').datagrid('reload');
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','SysDeployInfoView.html?' + '&appDeployId=' + row.appDeployId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}	

	function reloadList(){
		queryList();
		JLEUtil.closewin();
	};


	function doAction(action){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.restfulGet('../../api/sys/deploy/info/' + row.appDeployId+"/"+action,null,function(data){
				if (data.rows != "LoginFailure" && data.rows != "AppNotExist"){
					$('#dg').datagrid('reload');
						JLUtil.linkNewPage('ViewApplicationRunLog.html?appDeployId='+row.appDeployId
							+"&appName=" +row.appName
							+"&appCnname=" +row.appCnname
							+"&action=" +action
							+"&status="+data.rows);
				}else {
					if (data.rows=="LoginFailure"){
						alert("登陆服务器失败");
					}else {
						alert("应用路径不存在");
					}
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doManualDeploy(){
		var subsCode = $.getUrlParam("subsCode");
		JLUtil.linkNewPage('SysDeployInfoAdd.html?subsCode='+subsCode);
	}
	function visitApplicationWeb(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			var url = "http://"+row.ecsIp+":"+row.appPort+"/"+row.appName+"/";
			window.open(url);
		}else {
			$.messager.alert('提示','请选择一条记录！','info');
		}

	}
	function viewApplicationLogs(){
		var row = $('#dg').datagrid('getSelected');
		if (row){

			JLUtil.linkNewPage('ViewApplicationLogs.html?appDeployId='+row.appDeployId);
		}else {
			$.messager.alert('提示','请选择一条记录！','info');
		}

	}

</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" style="height: 40px; ">
	<form id="searchForm">
		<table>
			<tr>
				<td class="searchTd">应用名称：</td>
				<td><input name="appName" id="appName"/></td>
				<td class="searchTd">应用中文名称：</td>
				<td><input name="appCnname" id="appCnname"/></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="queryList()">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:95%"
			data-options="singleSelect:true,collapsible:true,fitColumns:true,method:'post'"
			toolbar="#tb"
		title="Load Data" 
		rownumbers="true" pagination="true" pageSize="20">
		<thead>
			<tr>
				<th data-options="field:'appDeployId',resizable:true" hidden="true">应用部署标识</th>
				<th data-options="field:'appId',resizable:true" hidden="true">应用标识</th>
				<th data-options="field:'appName',resizable:true" >应用名称</th>
				<th data-options="field:'appCnname',resizable:true" >应用中文名称</th>
				<th data-options="field:'appVersion',resizable:true" >应用版本</th>
				<th data-options="field:'appType',resizable:true" formatter="formatter_APP_TYPE">应用类型</th>
				<th data-options="field:'appOrder',resizable:true" >应用排列顺序</th>
				<th data-options="field:'ecsIp',resizable:true" >服务器IP</th>
				<th data-options="field:'ecsLoginUser',resizable:true" >服务器登陆用户</th>
				<th data-options="field:'ecsRegion',resizable:true" formatter="formatter_ECS_REGION">所在位置</th>
				<th data-options="field:'appDeployPath',resizable:true" >应用部署目录</th>
				<th data-options="field:'appLogPath',resizable:true" >应用日志目录</th>
				<th data-options="field:'appPort',resizable:true" >应用端口</th>
				<th data-options="field:'appState',resizable:true" formatter="formatter_APP_STATE">应用状态</th>
				<th data-options="field:'operTime',resizable:true" >操作时间</th>
				<th data-options="field:'operUserid',resizable:true" >操作人</th>
			</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
		<a href="javascript:doManualDeploy()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">手动部署</a>
		<a href="javascript:doView()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">查看应用部署信息</a>
		<a href="javascript:doAction('start')"  class="easyui-linkbutton" iconCls="icon-ok" plain="true">应用启动</a>
		<a href="javascript:doAction('stop')" class="easyui-linkbutton" iconCls="icon-ok" plain="true">应用停止</a>
		<a href="javascript:doAction('restart')" class="easyui-linkbutton" iconCls="icon-ok" plain="true">应用重启</a>
		<a href="javascript:visitApplicationWeb()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">访问应用</a>
		<a href="javascript:viewApplicationLogs()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">查看应用日志</a>
	</div>
</div>
</body>
</html>
